<template>
  <div class="view-fill">
    <div v-if="!modifyInfo.visible" class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        title="评价体系详情"
        :needOperateAffair="true"
        :operateAffairData="affairTableInfo"
      >
        <template v-slot:full-button>
          <el-button
            v-if="
              $permission('evaluationSystem:update') &&
              infoList.data.status === 0
            "
            @click="update"
            >修改</el-button
          >
        </template>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <basic-information :info="infoList"></basic-information>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('detailInfo') }}</p>
          </div>
          <div class="model-panel-body">
            <div class="layui-card-body">
              <!-- 表格 -->
              <page-table
                :refresh="tableInfo.refresh"
                :init-curpage="tableInfo.initCurpage"
                v-model:data="tableInfo.data"
                :pager="false"
                :field-list="tableInfo.fieldList"
                :handle="tableInfo.handle"
                :check-box="false"
                :tab-index="true"
                :isDynamic="true"
              >
              </page-table>
            </div>
          </div>
        </div>
      </NewFullScreen>
    </div>
    <modify
      v-if="modifyInfo.visible"
      :id="modifyInfo.id"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      @returnModify="returnModify"
    />
    <individualDetails
      v-if="individualInfo.visible"
      v-model:show-dialog="individualInfo.visible"
      :query="individualInfo.query"
      :info="individualInfo.info"
    />
  </div>
</template>

<script setup name="evaluationSystemDetails">
import BasicInformation from '@/components/BasicInformation/index'
import PageTable from '@/components/PageTable/index'
import Modify from './modify'
import individualDetails from './individualDetails'
import { orderOpAffairAll } from '@/api/affair'
import { getEvaluateTemplateById } from '@/api/evaluate.js'

const { proxy } = getCurrentInstance()
const emit = defineEmits()

const props = defineProps(['visible', 'tableRow'])

const infoList = reactive({
  data: {},
  fieldList: [
    {
      label: '评价体系名称',
      value: 'templateName',
    },
    {
      label: '评价体系编码',
      value: 'templateCode',
    },
    {
      label: '状态',
      value: 'statusValue',
    },
    {
      label: '创建人',
      value: 'createUserName',
    },
    {
      label: '创建时间',
      value: 'createTime',
    },
    {
      label: '更新人',
      value: 'updateUserName',
    },
    {
      label: '更新时间',
      value: 'updateTime',
    },
    {
      label: '备注',
      value: 'remark',
      type: 'popover',
    },
  ],
})
const modifyInfo = reactive({
  visible: false,
  id: '',
  title: '',
})
const tableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [],
  selections: [],
  fieldList: [
    { label: '评价分类名称', value: 'classifyName' },
    { label: '分值', value: 'classifyScore' },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '评价项目详情',
        event: evaluateItemsDetails,
        show: true,
      },
    ],
  },
})
const affairTableInfo = reactive({
  api: orderOpAffairAll,
  query: {
    orderType: 83,
    orderId: props.tableRow.id,
    sort: 'operate_time desc',
  },
})
const individualInfo = reactive({
  visible: false,
  query: {},
  info: {},
})

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emit('update:visible', newValue) // 更新父组件visible
  },
})

onMounted(() => {
  getMain()
})

function evaluateItemsDetails(row) {
  individualInfo.visible = true
  individualInfo.info = row
  console.log(individualInfo.visible)
}
function update() {
  modifyInfo.id = props.tableRow.id
  modifyInfo.title = '修改评价体系'
  modifyInfo.visible = true
}
function returnModify() {
  getMain()
}
function getMain() {
  getEvaluateTemplateById(props.tableRow.id).then((resp) => {
    if (resp && resp.success) {
      infoList.data = resp.data
      tableInfo.data = resp.data.classifyDetails
    }
  })
}
</script>

<style scoped></style>
